package com.sw.bbs.board.service.impl;

import com.sw.bbs.board.dao.media.TagMapper;
import com.sw.bbs.board.pojo.Tag;
import com.sw.bbs.board.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Desc: No Desc
 * @Author: wusonghe
 * @Date: 2019/4/23 9:33
 */
@Service
public class TagServiceImpl implements TagService {

    @Autowired
    private TagMapper tagMapper;

    @Override
    public void updateAndInsertTags(List<String> keywords) {
        for (String keyword :keywords) {
            Tag tag = tagMapper.queryTagByKeyword(keyword);
            if (tag!=null){
                tag.setSearchNum(tag.getSearchNum()+1);
                tagMapper.updateByPrimaryKeySelective(tag);
            }else  {
                tag = new Tag();
                tag.setName(keyword);
                tag.setType("search");
                tagMapper.insert(tag);
            }
        }
    }
}
